//
//  WXPAlreadyAuthGoLoanView.m
//  去借款
//
//  Created by wxp on 2025/3/8.
//

#import "WXPAlreadyAuthGoLoanView.h"

@implementation WXPAlreadyAuthGoLoanView

#pragma mark - lazy
- (UIView *)viewBack{
    if (_viewBack == nil) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.userInteractionEnabled = true;
        [GlobalMethod setRoundView:_viewBack color:[UIColor whiteColor] numRound:16 width:0];
    }
    return _viewBack;
}
- (UILabel *)labelTitle{
    if (_labelTitle == nil) {
        _labelTitle = [UILabel new];
        _labelTitle.textColor = COLOR_BLACK;
        _labelTitle.font = [UIFont boldSystemFontOfSize:16];
    }
    return _labelTitle;
}
- (UIView *)lineTitle{
    if (_lineTitle == nil) {
        _lineTitle = [UIView new];
        _lineTitle.widthHeight = XY(36, 6);
        [GlobalMethod setRoundView:_lineTitle color:[UIColor clearColor] numRound:6/2 width:0];
        _lineTitle.backgroundColor = COLOR_PRIMARY;
    }
    return _lineTitle;
}
- (UIView *)lineView{
    if (_lineView == nil) {
        _lineView = [UIView new];
        _lineView.backgroundColor = COLOR_LINE;
    }
    return _lineView;
}
- (UILabel *)labelMoneyTitle{
    if (_labelMoneyTitle == nil) {
        _labelMoneyTitle = [UILabel new];
        _labelMoneyTitle.textColor = COLOR_BLACK;
        _labelMoneyTitle.fontNum = (12);
    }
    return _labelMoneyTitle;
}
- (UILabel *)labelMoney{
    if (_labelMoney == nil) {
        _labelMoney = [UILabel new];
        _labelMoney.textColor = COLOR_RED;
        _labelMoney.font = [UIFont boldSystemFontOfSize:36];
    }
    return _labelMoney;
}
- (UIButton *)btnLoan{
    if (_btnLoan == nil) {
        _btnLoan = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnLoan.tag = 1;
        [_btnLoan addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnLoan.backgroundColor = COLOR_PRIMARY;
        [_btnLoan setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnLoan.titleLabel.font = [UIFont systemFontOfSize:14];
        _btnLoan.widthHeight = XY(160, BUTTON_HEIGHT);
        [GlobalMethod setRoundView:_btnLoan color:[UIColor clearColor] numRound:BUTTON_HEIGHT/2 width:0];
        [_btnLoan setTitle:@"Solicitar ahora" forState:(UIControlStateNormal)];
    }
    return _btnLoan;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, 0);
        self.backgroundColor = [UIColor clearColor];
        [self addSubView];
    }
    return self;
}
//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.lineTitle];
    [self.viewBack addSubview:self.labelTitle];
    [self.viewBack addSubview:self.lineView];
    [self.viewBack addSubview:self.labelMoneyTitle];
    [self.viewBack addSubview:self.labelMoney];
    [self.viewBack addSubview:self.btnLoan];
    [self resetViewWithMoney:@"0"];
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    if(self.blockGoLoan){
        self.blockGoLoan();
    }
}

#pragma mark - 刷新view
- (void)resetViewWithMoney:(NSString *)moneyStr{
    self.viewBack.widthHeight = XY(self.width-2*LEFT_MARDIN, 0);
    
    [self.labelTitle fitTitle:@"Pedir préstamo" variable:0];
    self.labelTitle.leftTop = XY(LEFT_MARDIN, LEFT_MARDIN);
    
    self.lineTitle.leftBottom = XY(self.labelTitle.left-1, self.labelTitle.bottom);
    
    self.lineView.widthHeight = XY(self.viewBack.width-2*LEFT_MARDIN, 1);
    self.lineView.centerXTop = XY(self.viewBack.width/2, self.lineTitle.bottom+13);
    
    [self.labelMoneyTitle fitTitle:@"Importe máximo($）" variable:0];
    self.labelMoneyTitle.leftTop = XY(self.labelTitle.left, self.lineView.bottom+LEFT_MARDIN);
    
    self.btnLoan.rightTop = XY(self.viewBack.width-self.labelTitle.left, self.labelMoneyTitle.bottom+8);
    
    [self.labelMoney fitTitle:[GlobalMethod showMoney:moneyStr] variable:0];
    self.labelMoney.leftCenterY = XY(self.labelTitle.left, self.btnLoan.centerY);
    
    self.viewBack.height = self.btnLoan.bottom + 16;
    self.viewBack.centerXTop = XY(self.width/2, 0);
    self.height = self.viewBack.bottom+LEFT_MARDIN;
}

@end
